﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using SMS.Entities;
using SMS.DAL;

namespace SMS.Web.Service
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "SupplierService" in code, svc and config file together.
    public class SupplierService : ISupplierService
    {

        public List<Entities.Supplier> SearchSupplier(string UserName, string SearchText, out SMSException serviceError)
        {
            try
            {
                SupplierDA da = new SupplierDA();
                var result = da.SearchObject(UserName, SearchText);
                serviceError = null;
                return result;
            }
            catch (Exception ex)
            {
                serviceError = new SMSException(ex);
                return null;
            }
        }

        public int SaveSupplier(string userName, Supplier supplier, out SMSException serviceError)
        {
            try
            {
                var retObj = new SupplierDA().SaveObject(userName, supplier);
                serviceError = null;
                return retObj.Supplier_ID;
            }
            catch (Exception ex)
            {
                serviceError = new Entities.SMSException(ex);
                return -1;
            }
        }


        public Supplier GetCompleteSupplier(string UserName, int Id, out SMSException ServiceErrror)
        {
            try
            {
                var retObj = new SupplierDA().GetCompleteSupplierObject(UserName, Id);
                ServiceErrror = null;
                return retObj;
            }
            catch (Exception ex)
            {
                ServiceErrror = new SMSException(ex);
                return null;
            }
        }
    }
}
